/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chapter6;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Denise Carolina
 */
public class Directories {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PrintWriter pw = null;
        try {
            File dir = new File("myDir");
            dir.mkdir();
            File file1 = new File(dir, "file1.txt");
            pw = new PrintWriter(file1);
            pw.write("text 1\n");
            pw.write("text 2");

            File newDir = new File("newDir");
            newDir.mkdir();
            System.out.println(newDir.isDirectory());
            File file2 = new File(newDir, "file2.txt");
            file2.createNewFile();

            File file3 = new File(newDir, "file3.txt");
            file3.createNewFile();
            file3.renameTo(new File(newDir, "renamed.txt"));
            file3.delete();
            System.out.println(file3.exists());
            System.out.println(newDir.delete());

            File newDir2 = new File("newDir2");
            newDir.renameTo(newDir2);

            String [] elem = newDir.list();
            for (String s: elem){
                System.out.println("s:: " + s);
            }

            File newDir3 = new File("newDir3");
            newDir2.renameTo(newDir3);

            File newDir4 = new File("newDir4");
            newDir4.mkdir();
            newDir4.delete();
            System.out.println("direc4:: " + newDir4.isDirectory());

        } catch (IOException ex) {
            Logger.getLogger(Directories.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            pw.close();
        }

    }

}
